package com.example.leetdemo.finash;

import java.time.LocalDateTime;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalField;
import java.time.temporal.WeekFields;
import java.util.Arrays;

public class Solution16 {

    public int threeSumClosest(int[] nums, int target) {
        Arrays.sort(nums);
        int dif = 10000007;
        for (int i = 0; i < nums.length - 2; i++) {
            int p = i + 1, q = nums.length - 1;
            while (p < q) {
                int t = nums[i] + nums[p] + nums[q];
                if (t == target) {
                    return t;
                }
                dif = Math.abs(target - dif) > Math.abs(target - t) ? t : dif;
                if (t > target) {
                    q--;
                }
                if (t < target) {
                    p++;
                }
            }
        }
        return dif;
    }

    public static void main(String[] args) {
        Solution16 solution16 = new Solution16();
        System.err.println(solution16.threeSumClosest(new int[]{-1, 2, 1, -4}, 1));
        System.err.println(LocalDateTime.now().plusDays(-2L).get(ChronoField.ALIGNED_WEEK_OF_YEAR));

        System.err.println(1569 * 714 * 170);
    }

    public String categorizeBox(int length, int width, int height, int mass) {
        String[] result = new String[] {"Neither", "Bulky", "Heavy", "Both"};
        int k = 0;
        int max_length = 10000, max_v = 1000000000;
        if (length > max_length || width > max_length || height > max_length) {
            k += 1;
        } else if (max_v < ((long) length * width) * height) {
            k += 1;
        }
        if (mass > 100) {
            k += 2;
        }
        return result[k];
    }

}
